#pragma once
#include<string>
#include<concepts>
#include<map>
#include<vector>
#include<sstream>
/**
* @param:data bedore serialize
* @return:data after serialize
*/
std::string serialize(const std::string&);
std::pair<std::string,std::string> deserialize(const std::string&);
std::pair<std::uint64_t, std::string> deserialize_head(const std::string&);
std::vector<std::string> split(const std::string&, char ch);
std::string join(const std::vector<std::string>&, char ch);
std::string trim(const std::string& str);
template<typename TO,typename FROM>
TO convert(const FROM& from) {
	std::stringstream conv;
	conv << from;
	TO res;
	conv >> res;
	return res;
}
template<typename T>
concept integral = std::is_integral<T>::value;
template<integral T>
std::string transfer_to_byte(T value) {
	constexpr std::size_t len = sizeof(T);
	std::string res(len,'\0');
	res.shrink_to_fit();
	for (int i = 0; i < len; i++) {
		res[i] = '\0';
		res[i] |= (static_cast<T>(0xff) & (value >> i));
	}
	return res;
}
template<integral T>
T transfer_from_byte(const std::string& bytes) {
	constexpr std::size_t len = sizeof(T);
	T res = 0;
	for (int i = 0; i < len; i++) {
		res |= (static_cast<T>(bytes[i]) << i);
	}
	return res;
}